#pragma once

#include <functional>
#include <string>

#include <git2/remote.h>

#include "git-cert-provider.h"

namespace git
{

class FetchContext
{
public:
    using ProgressCallback = std::function<void(const std::string &)>;

    FetchContext(const Cert &cert, git_fetch_options &opt);

    void setProgressCallback(ProgressCallback &&callback);

private:
    void bind(git_fetch_options &opt) const;

    static int onFetchSidebandProgress(const char *str, int len, void *payload);

    static int onFetchTransferProgress(const git_indexer_progress *stats, void *payload);

    static int onFetchCredential(git_credential **out,
        const char *url,
        const char *usernameFromUrl,
        unsigned int allowedTypes,
        void *payload);

private:
    const CertProvider certProvider_;
    ProgressCallback progressCallback_;
};

} // namespace git
